//
//  Inventory.cpp
//  party-family
//
//  Created by Justin Kurtz on 6/27/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#include "Inventory.h"

Inventory::Inventory()
{
}

Inventory::~Inventory()
{
   
}

// not sure if this will be usefull yet.
void Inventory::Use(Item *item)
{
   if(HasItem(item)) {
      item->Use();
   }
}

// Returns true if method failed to add item.
bool Inventory::PickupItem(Item *item)
{
   bool retVal = false;
   if(IsFull()) {
      retVal = true;
   }
   else {
      inventory.push_back(*item);
   }
   
   return retVal;
}

// remove the item at the 0 based index of the inventory
// returns true for failure
bool Inventory::DropItem(unsigned int index)
{
   bool retVal = false;
   
   if(inventory.size() >= (index + 1)) {
      retVal = true;
   }
   else {
      inventory.at(index).HasBeenDropped();
      inventory.erase(inventory.begin() + index);
   }
   
   return retVal;
}

// returns true for failure
bool Inventory::DropItem(Item *item)
{
   bool retVal = true;
   for (unsigned int i = 0; i < inventory.size(); i++) {
      if (inventory.at(i) == *item)
      {
         retVal = false;
         inventory.at(i).HasBeenDropped();
         inventory.erase(inventory.begin() + i);
         break;
      }
   }
   return retVal;
}

// returns true if inventory has the item
bool Inventory::HasItem(Item *item)
{
   bool retVal = false;
   for (unsigned int i = 0; i < inventory.size(); i++) {
      if (inventory.at(i) == *item)
      {
         retVal = true;
         break;
      }
   }
   return retVal;
}

bool Inventory::IsEmpty()
{
   bool retVal = true;
   
   if (inventory.size() > 0) {
      retVal = false;
   }
   
   return retVal;
}

bool Inventory::IsFull()
{
   bool retVal = true;
   if (inventory.size() < maxItems) {
      retVal = false;
   }
   
   return retVal;
}

int Inventory::GetNumItems()
{
   return (int)inventory.size();
}
